//package com.zdd.ehe.neo4j.service.impl;
//
//import com.zdd.ehe.neo4j.entity.DiseaseNode;
//import com.zdd.ehe.neo4j.service.KnowledgeGraphService;
//import com.zdd.ehe.vo.EdgeVo;
//import com.zdd.ehe.vo.KnowledgeGraphVo;
//import com.zdd.ehe.vo.NodeVo;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.neo4j.core.Neo4jClient;
//import org.springframework.stereotype.Service;
//
//import java.util.*;
//
///**
// * @version 1.0.0
// * @title: KnowledgeGraphServiceImpl
// * @author: HFLy
// * @description:
// * @date: 10/3/2023 下午4:28
// */
//@Service
//public class KnowledgeGraphServiceImpl implements KnowledgeGraphService {
//    @Autowired
//    Neo4jClient neo4jClient;
//
//    @Override
//    public KnowledgeGraphVo getKnowledgeGraph() {
//        //第一层 类型
//        List<NodeVo> nodes = (ArrayList<NodeVo>) neo4jClient.query("match (t:Type)-[属于]- (b:Botanys) return id(t) as id,t.name as name,0 as level,count(b) as childrenNum,id(t) as tag")
//                .fetchAs(NodeVo.class)
//                .mappedBy(((typeSystem, record) -> {
//                    NodeVo nodeVo = new NodeVo();
//                    nodeVo.setId(String.valueOf(record.get("id").asInt()));
//                    nodeVo.setName(record.get("name").asString());
//                    nodeVo.setLevel(record.get("level").asInt());
//                    nodeVo.setChildrenNum(record.get("childrenNum").asInt());
//                    nodeVo.setTag(String.valueOf(record.get("tag").asInt()));
//                    return nodeVo;
//                })).all();
//        //第二层 植物
//        nodes.addAll(neo4jClient.query("match (t:Type) -[属于]-(b:Botanys)-[迫害对象]-(d:Disease) return id(b) as id,b.name as name,1 as level,count(d) as childrenNum,id(b) as tag,id(t) as tags")
//                .fetchAs(NodeVo.class)
//                .mappedBy(((typeSystem, record) -> {
//                    NodeVo nodeVo = new NodeVo();
//                    nodeVo.setId(String.valueOf(record.get("id").asInt()));
//                    nodeVo.setName(record.get("name").asString());
//                    nodeVo.setLevel(record.get("level").asInt());
//                    nodeVo.setChildrenNum(record.get("childrenNum").asInt());
//                    nodeVo.setTag(String.valueOf(record.get("tag").asInt()));
//                    ArrayList<String> tags = new ArrayList<>();
//                    tags.add(String.valueOf(record.get("tags").asInt()));
//                    nodeVo.setTags(tags);
//                    return nodeVo;
//                })).all()
//        );
//        //第三层 病虫害
//        nodes.addAll(neo4jClient.query("match (t:Type)-[属于]-(b:Botanys)-[迫害对象]-(d:Disease) return id(d) as id,d.name as name,2 as level,0 as childrenNum,true as isLeaf,id(b) as tags")
//                .fetchAs(NodeVo.class)
//                .mappedBy(((typeSystem, record) -> {
//                    NodeVo nodeVo = new NodeVo();
//                    nodeVo.setId(String.valueOf(record.get("id").asInt()));
//                    nodeVo.setName(record.get("name").asString());
//                    nodeVo.setLevel(record.get("level").asInt());
//                    nodeVo.setChildrenNum(record.get("childrenNum").asInt());
//                    nodeVo.setLeaf(record.get("isLeaf").asBoolean());
//                    ArrayList<String> tags = new ArrayList<>();
//                    tags.add(String.valueOf(record.get("tags").asInt()));
//                    nodeVo.setTags(tags);
//                    return nodeVo;
//                })).all()
//        );
//
//        List<EdgeVo> edges = (ArrayList<EdgeVo>) neo4jClient.query("match (s)-[re]-(t) where re.name in ['属于','迫害对象']  return id(s) as source,id(t) as target,type(re) as label")
//                .fetchAs(EdgeVo.class)
//                .mappedBy(((typeSystem, record) -> {
//                    return new EdgeVo(String.valueOf(record.get("source").asInt()),String.valueOf(record.get("target").asInt()),record.get("label").asString());
//                })).all();
//        return new KnowledgeGraphVo(nodes,edges);
//    }
//
//    @Override
//    public DiseaseNode queryDiseaseNodeById(Integer id) {
//        Optional<DiseaseNode> diseaseNode = neo4jClient.query("match (d:Disease)-[英文名]-(y:Y_name) where id(d) = "+id+" return id(d) as id,d.name as name,y.name as ename,d.介绍 as introduce,d.危害症状 as symptom,d.发生原因 as cause,d.防治办法 as measure,d.图片 as picture")
//                .fetchAs(DiseaseNode.class)
//                .mappedBy(((typeSystem, record) -> {
//                    DiseaseNode node = new DiseaseNode(record.get("id").asInt(),
//                            record.get("name").asString(),
//                            record.get("ename").asString(),
//                            record.get("introduce").asString(),
//                            record.get("symptom").asString(),
//                            record.get("cause").asString(),
//                            record.get("measure").asString(),
//                            record.get("picture").asString()
//                    );
//                    return node;
//                })).one();
//        return diseaseNode.get();
//    }
//
//}
